#pragma QueaTree

#include <so_math.h>
#include <list>
#include <vector>
#include <CollisionEntity.h>
class QuadTree
{
private:
    int objects_max;
    int deep_max;
    int current_deep;
    std::list<CollisionEntity *> *objects_list;
    std::vector<QuadTree *> *nodes_list;
    CollisionEntityRectangle rect;

public:
    QuadTree(const CollisionEntityRectangle &rect, int current_deep = 0, int objects_max = 8, int deep_max = 5);
    ~QuadTree();
    void insert(CollisionEntity *entity);
    void clear();
    std::list<CollisionEntity *> *retrieve(CollisionEntity *entity, std::list<CollisionEntity *> *returnObjects = nullptr) const;
    std::list<const CollisionEntityRectangle*>* getRectangles(std::list<const CollisionEntityRectangle *> *returnRectangles = nullptr) const;

private:
    int getInsertIndex(CollisionEntity *entity) const;
    void split();
};